<!--  -->
<template>
  <div class="qq-music-list">
    <h1>歌 单 推 荐</h1>
    <ul>
      <li v-for="item in songListName" :key="item.id">
        <a
          href="javascript:;"
          @click="getsonglist(item.cat)"
          :class="[{ green: isGreen === item.cat }]"
          >{{ item.name }}</a
        >
      </li>
    </ul>
    <div class="song-list">
      <div class="list" v-for="item in songList" :key="item.id">
        <div class="list-box">
          <div class="imgbox">
            <div class="mask">
              <img
                src="https://y.gtimg.cn/mediastyle/yqq/img/cover_play@2x.png?max_age=2592000&v=88abebcbc1242dbbbbc836cc3e04a006&v=88abebcbc1242dbbbbc836cc3e04a006&v=10e4305a2558d496548955434eaa30d9"
                alt=""
              />
            </div>
            <img :src="item.coverImgUrl" alt="" />
          </div>

          <p>{{ item.name }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      isGreen: "全部",
      cat: "全部",
      songList: [],
      songListName: [
        { name: "推荐", id: 1, cat: "全部" },
        { name: "华语", id: 2, cat: "华语" },
        { name: "古风", id: 3, cat: "古风" },
        { name: "欧美", id: 4, cat: "欧美" },
        { name: "流行", id: 5, cat: "流行" },
      ],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getlist: async function () {
      let res = await this.$http.get("top/playlist/highquality", {
        params: {
          limit: 5,
          cat: this.cat,
        },
      });
      this.songList = res.data.playlists;
      //   console.log(res)
    },
    getsonglist: function (cat) {
      this.isGreen = cat;
      this.cat = cat;
      this.getlist();
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getlist();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
.qq-music-list {
  background: -webkit-linear-gradient(top, #eee, white);

  margin: 0 auto;
  text-align: center;
  margin-bottom: 40px;
  overflow: hidden;
  h1 {
    margin: 20px 0;
    font-weight: 500;
  }
  ul {
    display: flex;
    width: 600px;
    margin: 0 auto;
    justify-content: space-between;
    margin-bottom: 20px;
    li {
      list-style: none;
      a {
        text-decoration: none;
        color: #000;
      }
      a:hover {
        color: #31c27c;
      }
      .green {
        color: #31c27c;
      }
    }
  }
  .song-list {
    display: flex;
    justify-content: space-between;
    width: 1200px;
    margin: 0 auto;
    .list {
      .list-box {
        cursor: pointer;
        .imgbox {
          width: 220px;
          height: 220px;
          position: relative;
          overflow: hidden;
          .mask {
            width: 220px;
            height: 220px;
            opacity: 0;
            position: absolute;
            transition: all 0.5s linear;
            background: rgba(30, 30, 30, 0.2);
            img {
              position: absolute;
              top: 76px;
              left: 76px;
              width: 70px;
              height: 70px;
            }
          }
          img {
            width: 220px;
            height: 220px;
            transition: all 0.5s linear;
            margin-bottom: 10px;
          }
        }
        .imgbox:hover {
          .mask {
            opacity: 1;
            z-index: 999;
          }
          img {
            transform: scale(1.1);
          }
        }
        p {
          margin-top: 10px;
          font-size: 14px;
          width: 220px;
          text-align: left;
        }
        p:hover {
          color: #31c27c;
        }
      }
    }
  }
}
</style>